package com.deng.common.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.deng.common.SQLHelper;
import com.deng.common.dao.IHisOrganiation;
import com.deng.common.vo.HisOrganizationVo;

public class HisOrganizationImpl extends SQLHelper implements IHisOrganiation {

	public List<HisOrganizationVo> getAllData() {
		try{
			Connection con = getConnect();
			ResultSet rs = queryData(con,"select * from t_sys_his_department order by his_dept_code");
			List<HisOrganizationVo> l = new ArrayList<HisOrganizationVo>();
			HisOrganizationVo vo;
			while(rs.next()){
				vo = new HisOrganizationVo();
				vo.code = rs.getString("his_dept_code");
				vo.name = rs.getString("his_dept_name");
				l.add(vo);
			}
			return l;
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}

	public List<HisOrganizationVo> getHisByOrganizationId(int organization_id) {
		try{
			Connection con = getConnect();
			ResultSet rs = queryData(con,
					"select t_sys_his_department.his_dept_code,t_sys_his_department.his_dept_name" +
					"	from t_sys_stat_department_vs_original_department,t_sys_his_department" +
					"	where t_sys_stat_department_vs_original_department.stat_id = " +organization_id+
					"	and t_sys_stat_department_vs_original_department.original_id = his_dept_code");
			List<HisOrganizationVo> l = new ArrayList<HisOrganizationVo>();
			HisOrganizationVo vo;
			while(rs.next()){
				vo = new HisOrganizationVo();
				vo.code = rs.getString("his_dept_code");
				vo.name = rs.getString("his_dept_name");
				l.add(vo);
			}
			return l;
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}

}
